﻿<template>
    <div>
        <div>
            <hr />
            <h3>登录</h3>
            <!-- <form action="http://y39406f563.51vip.biz/" method="get"> -->
                <input type="text" v-model="username" placeholder="请输入你的名字" /><br />
                <input type="text" v-model="userPasswd" placeholder="请输入你的密码" /><br />
                <input type="submit" value="登录" @click="RegBtn">
            <!-- </form> -->
        </div>
        <h3 v-cloak>你的id是{{userId}}</h3>
    </div>
</template>

<script>
    import axios from 'axios'
    export default {
        name: 'Login',
        components: {},
        data() {
            return {
                userId:'',
                username:'',
                userPasswd:''
            }
        },
        beforeCreate(){
            this.$bus.$on('sendLogin',(data)=>{
                console.log('接收到了数据',data)
            })
        },
        mounted(){
            
        },
        beforeDestroy(){
            this.$bus.$off('sendLogin')
        },
        methods: {
            RegBtn(){
                axios.get(`localhost:8085/${this.username}/${this.userPasswd}`).then(
                    response=>{
                        console.log('请求成功了',response.data)
                        this.userId = response.data.id
                    },
                    error=>{
                        console.log('请求失败了',error.message)
                    }
                )
            }
        },
    }
</script>

<style scoped>
    [v-cloak]{display: none;}
</style>